package com.struggle.rabbitmqconsumer.config;

import com.struggle.common.ExchangeConstants;
import com.struggle.common.QueueConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className FanoutRabbitConfig
 * @Description 订阅模式消费者配置类
 * @Author liuwj3
 * @Date 2019/10/12 0012 下午 4:13
 **/
@Configuration
public class FanoutRabbitConfig {
    /**
     *  创建三个队列 ：fanoutA   fanoutB  fanoutC
     *  将三个队列都绑定在交换机 fanoutExchange 上
     *  因为是扇型交换机, 路由键无需配置,配置也不起作用
     */

    @Bean
    public FanoutExchange getFanoutExchange() {
        return new FanoutExchange(ExchangeConstants.FANOUT_EXCHANGE);
    }
    @Bean
    public Queue getQueueA() {
        return new Queue(QueueConstants.FANOUT_QUEUE_A);
    }
    @Bean
    public Queue getQueueB() {
        return new Queue(QueueConstants.FANOUT_QUEUE_B);
    }
    @Bean
    public Queue getQueueC() {
        return new Queue(QueueConstants.FANOUT_QUEUE_C);
    }

    @Bean
    public Binding bindingExchangeA() {
        return BindingBuilder.bind(getQueueA()).to(getFanoutExchange());
    }
    @Bean
    public Binding bindingExchangeB() {
        return BindingBuilder.bind(getQueueB()).to(getFanoutExchange());
    }
    @Bean
    public Binding bindingExchangeC() {
        return BindingBuilder.bind(getQueueC()).to(getFanoutExchange());
    }
}
